home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 008 / src / mklev.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  15KB  |  668 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* mklev.c version 1.0.1 - new makecorridor() */
  3. #ifndef MKLEV
  4. #define    MKLEV
  5. #endif
  6. #include <stdio.h>
  7. #include "hack.h"
  8. #include "def.trap.h"
  9.  
  10. extern struct monst *makemon();
  11.  
  12. static char tspe[2],**args;
  13. static int doorindex;
  14. static schar nxcor;
  15.  
  16. char ismklev;
  17. struct mkroom *croom, *troom;
  18. boolean goldseen;
  19. int nroom;
  20. int smeq[MAXNROFROOMS+1];
  21. char *tfile;
  22.  
  23. #ifdef WIZARD
  24. extern boolean wizard;
  25. #endif
  26.  
  27. #define somex() ((rand()%(croom->hx-croom->lx+1))+croom->lx)
  28. #define somey() ((rand()%(croom->hy-croom->ly+1))+croom->ly)
  29.  
  30. extern char nul[40];
  31. extern struct rm levl[COLNO][ROWNO];
  32. extern struct monst *fmon;
  33. extern struct obj *fobj;
  34. extern struct gen *fgold, *ftrap;
  35. extern char *fut_geno;      /* monsters that should not be created anymore */
  36. extern struct mkroom rooms[MAXNROFROOMS+1];
  37. extern coord doors[DOORMAX];
  38. extern int comp();
  39. extern xchar dlevel;
  40. extern xchar xdnstair,xupstair,ydnstair,yupstair;
  41.    
  42. zeroout(addr, len)
  43. char *addr;
  44. int len;
  45. {
  46.     while(--len>0) *addr++=0;
  47. }
  48.  
  49. mklev()
  50. {
  51.     register unsigned tryct;
  52.  
  53.     tfile = lock;
  54.     troom = NULL;
  55.     doorindex = 0;
  56.     nroom = 0;
  57.  
  58.     if(getbones()) return;
  59.     ismklev = 1;
  60.     if(dlevel < rn1(3, 26)) tspe[0] = 'a';   /* normal level */
  61.     else tspe[0] = 'b';         /* maze */
  62.     tspe[1] = 0;
  63.  
  64.     /* zap the object bases */
  65.     {int i;extern int bases[];
  66.     for(i=0;i<15;bases[i++]=0);}
  67.  
  68.     /* zap the room pictures */
  69.     zeroout(levl,COLNO*ROWNO*sizeof(struct rm));
  70.  
  71.     fmon = NULL;
  72.     fobj = NULL;
  73.     fgold = ftrap = NULL;
  74.    
  75.     zeroout( doors, sizeof(coord)*DOORMAX);
  76.  
  77.     xdnstair = xupstair = ydnstair = yupstair = 0;
  78.     zeroout(rooms, (MAXNROFROOMS+1)*sizeof(struct mkroom));
  79.  
  80.     init_objects();
  81.     rooms[0].hx = -1;   /* in case we are in a maze */
  82.  
  83.     /* a: normal; b: maze */
  84.     if(*tspe == 'b') {
  85.         makemaz();
  86. #ifdef DOSAVE
  87.         {
  88.         int fd;
  89.         if((fd = creat(tfile,FMASK)) < 0) 
  90.             panic("Cannot create %s\n", tfile);
  91.         savelev(fd);
  92.         close(fd);
  93.         }
  94. #endif
  95.         ismklev = 0;
  96.         return(0);
  97.     }
  98.  
  99.     /* construct the rooms */
  100.     while(nroom < (MAXNROFROOMS/3)) {
  101.         croom = rooms;
  102.         nroom = 0;
  103.         (void) makerooms(0);      /* not secret */
  104.     }
  105.  
  106.     /* for each room: put things inside */
  107.     for(croom = rooms; croom->hx > 0; croom++) {
  108.  
  109.         /* put a sleeping monster inside */
  110.         if(!rn2(3)) (void)
  111.             makemon((struct permonst *) 0, somex(), somey());
  112.  
  113.         /* put traps and mimics inside */
  114.         goldseen = FALSE;
  115.         while(!rn2(8-(dlevel/6))) mktrap(0,0);
  116.         if(!goldseen && !rn2(3)) mkgold(0,somex(),somey());
  117.         if(!rn2(3)) {
  118.             mkobj_at(0, somex(), somey());
  119.             tryct = 0;
  120.             while(!rn2(5)) {
  121.                 if(++tryct > 100){
  122.                     myprintf("tryct overflow4\n");
  123.                     break;
  124.                 }
  125.                 mkobj_at(0, somex(), somey());
  126.             }
  127.         }
  128.     }
  129.     tryct = 0;
  130.     do {
  131.         if(++tryct > 1000) panic("Cannot make dnstairs\n");
  132.         croom = &rooms[rn2(nroom)];
  133.         xdnstair = somex();
  134.         ydnstair = somey();
  135.     } while((*tspe =='n' && (!(xdnstair%2) || !(ydnstair%2))) ||
  136.         g_at(xdnstair,ydnstair,ftrap));
  137.     levl[xdnstair][ydnstair].scrsym ='>';
  138.     levl[xdnstair][ydnstair].typ = STAIRS;
  139.     troom = croom;
  140.     do {
  141.         if(++tryct > 2000) panic("Cannot make upstairs\n");
  142.         croom = &rooms[rn2(nroom)];
  143.         xupstair = somex();
  144.         yupstair = somey();
  145.     } while(croom == troom || m_at(xupstair,yupstair) ||
  146.         g_at(xupstair,yupstair,ftrap));
  147.     levl[xupstair][yupstair].scrsym ='<';
  148.     levl[xupstair][yupstair].typ = STAIRS;
  149.  
  150. #ifdef DEBUG
  151.     dumpit();
  152. #endif
  153.     qsort((char *) rooms, nroom, sizeof(struct mkroom), comp);
  154.     makecorridors();
  155.     make_niches();
  156.  
  157.     /* make a secret treasure vault, not connected to the rest */
  158.     if(nroom < (2*MAXNROFROOMS/3)) if(!rn2(3)) {
  159.         register int x,y;
  160.         troom = croom = &rooms[nroom];
  161.         if(makerooms(1)) {      /* make secret room */
  162.             troom->rtype = 6;      /* treasure vault */
  163.             for(x = troom->lx; x <= troom->hx; x++)
  164.             for(y = troom->ly; y <= troom->hy; y++)
  165.                 mkgold(rnd(dlevel*100) + 50, x, y);
  166.             if(!rn2(3))
  167.                 makevtele();
  168.         }
  169.     }
  170.  
  171. #ifdef WIZARD
  172.     if(wizard){
  173.         if(rn2(3)) mkshop(); else mkzoo();
  174.     } else
  175. #endif WIZARD
  176.     if(dlevel > 1 && dlevel < 20 && rn2(dlevel) < 2)
  177.         mkshop();
  178.     else
  179.         if(dlevel > 6 && !rn2(7) )
  180.             mkzoo();
  181. #ifdef DOSAVE
  182.     {
  183.     int fd;
  184.     if((fd = creat(tfile,FMASK)) < 0) 
  185.         panic("Cannot create %s\n", tfile);
  186.     savelev(fd);
  187.     close(fd);
  188.     }
  189. #endif
  190.     ismklev = 0;
  191.     return(0);
  192. }
  193.  
  194. makerooms(secret)
  195. int secret;
  196. {
  197.     register int lowx, lowy;
  198.     register int tryct = 0;
  199.  
  200.    while(nroom < (MAXNROFROOMS/2) || secret)
  201.       for(lowy = rn1(3,3); lowy < ROWNO-7; lowy += rn1(2,4))
  202.          {
  203.          for(lowx = rn1(3,4); lowx < COLNO-10; lowx += rn1(2,7))
  204.             {
  205.             if (tryct++ > 10000) return(0);
  206.  
  207.             if ((lowy += (rn2(5)-2)) < 3)
  208.                lowy = 3;
  209.             else
  210.                if(lowy > ROWNO-6)
  211.                   lowy = ROWNO-6;
  212.  
  213.             if(levl[lowx][lowy].typ) continue;
  214.  
  215.             if ((secret && maker(lowx, 1, lowy, 1)) ||
  216.                 (!secret && maker(lowx,rn1(9,2),lowy,rn1(4,2))
  217.                 && nroom+2 > MAXNROFROOMS)) return(1);
  218.             }
  219.          }
  220.     return(1);
  221. }
  222.  
  223. comp(x,y)
  224. register struct mkroom *x,*y;
  225. {
  226.    if(x->lx < y->lx) return(-1);
  227.    return(x->lx > y->lx);
  228. }
  229.  
  230. coord
  231. finddpos(xl,yl,xh,yh) {
  232. coord ff;
  233. register int x,y;
  234.    ff.x = (xl == xh) ? xl : (xl + rn2(xh-xl+1));
  235.    ff.y = (yl == yh) ? yl : (yl + rn2(yh-yl+1));
  236.    if(okdoor(ff.x, ff.y)) return(ff);
  237.    if(xl < xh) for(x = xl; x <= xh; x++)
  238.       if(okdoor(x, ff.y)){
  239.          ff.x = x;
  240.          return(ff);
  241.       }
  242.    if(yl < yh) for(y = yl; y <= yh; y++)
  243.       if(okdoor(ff.x, y)){
  244.          ff.y = y;
  245.          return(ff);
  246.       }
  247.    return(ff);
  248. }
  249.  
  250. /* if allowable, create a door at [x,y] */
  251. okdoor(x,y)
  252. register int x,y;
  253. {
  254.     if(levl[x-1][y].typ == DOOR || levl[x+1][y].typ == DOOR ||
  255.        levl[x][y+1].typ == DOOR || levl[x][y-1].typ == DOOR ||
  256.        levl[x-1][y].typ == SDOOR || levl[x+1][y].typ == SDOOR ||
  257.        levl[x][y-1].typ == SDOOR || levl[x][y+1].typ == SDOOR ||
  258.        (levl[x][y].typ != HWALL && levl[x][y].typ != VWALL) ||
  259.        doorindex >= DOORMAX)
  260.         return(0);
  261.     return(1);
  262. }
  263.  
  264. dodoor(x,y,aroom)
  265. register int x,y;
  266. register struct mkroom *aroom;
  267. {
  268.     if(doorindex >= DOORMAX) panic("DOORMAX exceeded?");
  269.     if(!okdoor(x,y) && nxcor) return;
  270.     dosdoor(x,y,aroom,rn2(8) ? DOOR : SDOOR);
  271. }
  272.  
  273. dosdoor(x,y,aroom,type)
  274. register int x,y;
  275. register struct mkroom *aroom;
  276. register int type;
  277. {
  278.     register struct mkroom *broom;
  279.     register int tmp;
  280.  
  281.     levl[x][y].typ = type;
  282.     if(type == DOOR)
  283.         levl[x][y].scrsym ='+';
  284.     aroom->doorct++;
  285.     broom = aroom+1;
  286.     if(broom->hx < 0) tmp = doorindex; else
  287.     for(tmp = doorindex; tmp > broom->fdoor; tmp--)
  288.         doors[tmp] = doors[tmp-1];
  289.     doorindex++;
  290.     doors[tmp].x = x;
  291.     doors[tmp].y = y;
  292.     for( ; broom->hx >= 0; broom++) broom->fdoor++;
  293. }
  294.  
  295. /* Only called from makerooms() */
  296. maker(lowx,ddx,lowy,ddy)
  297. schar lowx,ddx,lowy,ddy;
  298. {
  299.     register int x, y, hix = lowx+ddx, hiy = lowy+ddy;
  300.  
  301.     if(nroom >= MAXNROFROOMS) return(0);
  302.     if(hix > COLNO-5) hix = COLNO-5;
  303.     if(hiy > ROWNO-4) hiy = ROWNO-4;
  304. chk:
  305.     if(hix <= lowx || hiy <= lowy) return(0);
  306.  
  307.     /* check area around room (and make room smaller if necessary) */
  308.     for(x = lowx-4; x <= hix+4; x++)
  309.         for(y = lowy-3; y <= hiy+3; y++)
  310.             if(levl[x][y].typ) {
  311.                 if(rn2(3)) return(0);
  312.                 lowx = x+5;
  313.                 lowy = y+4;
  314.                 goto chk;
  315.             }
  316.  
  317.     /* on low levels the room is lit (usually) */
  318.     /* secret vaults are always lit */
  319.     if((rnd(dlevel) < 10 && rn2(77)) || (ddx == 1 && ddy == 1))
  320.         for(x = lowx-1; x <= hix+1; x++)
  321.             for(y = lowy-1; y <= hiy+1; y++)
  322.                 levl[x][y].lit = 1;
  323.     croom->lx = lowx;
  324.     croom->hx = hix;
  325.     croom->ly = lowy;
  326.     croom->hy = hiy;
  327.     croom->rtype = croom->doorct = croom->fdoor = 0;
  328.     for(x = lowx-1; x <= hix+1; x++)
  329.         for(y = lowy-1; y <= hiy+1; y += (hiy-lowy+2)) {
  330.         levl[x][y].scrsym = '-';
  331.         levl[x][y].typ = HWALL;
  332.     }
  333.     for(x = lowx-1; x <= hix+1; x += (hix-lowx+2))
  334.         for(y = lowy; y <= hiy; y++) {
  335.         levl[x][y].scrsym = '|';
  336.         levl[x][y].typ = VWALL;
  337.     }
  338.     for(x = lowx; x <= hix; x++)
  339.         for(y = lowy; y <= hiy; y++) {
  340.         levl[x][y].scrsym = '.';
  341.         levl[x][y].typ = ROOM;
  342.     }
  343.     croom++;
  344.     croom->hx = -1;
  345.     smeq[nroom] = nroom;
  346.     nroom++;
  347.     return(1);
  348. }
  349.  
  350. makecorridors() {
  351.     register int a,b;
  352.  
  353.     nxcor = 0;
  354.     for(a = 0; a < nroom-1; a++)
  355.         join(a, a+1);
  356.     for(a = 0; a < nroom-2; a++)
  357.         if(smeq[a] != smeq[a+2])
  358.         join(a, a+2);
  359.     for(a = 0; a < nroom; a++)
  360.         for(b = 0; b < nroom; b++)
  361.         if(smeq[a] != smeq[b])
  362.             join(a, b);
  363.     if(nroom > 2)
  364.         for(nxcor = rn2(nroom) + 4; nxcor; nxcor--) {
  365.         a = rn2(nroom);
  366.         b = rn2(nroom-2);
  367.         if(b >= a) b += 2;
  368.         join(a, b);
  369.         }
  370. }
  371.  
  372. join(a,b)
  373. register int a,b;
  374. {
  375.     coord cc,tt;
  376.     register int tx, ty, xx, yy;
  377.     register struct rm *crm;
  378.     register int dx, dy, dix, diy, cct;
  379.  
  380.     croom = &rooms[a];
  381.     troom = &rooms[b];
  382.  
  383.     /* find positions cc and tt for doors in croom and troom
  384.        and direction for a corridor between them */
  385.  
  386.    if(troom->hx < 0 || croom->hx < 0 || doorindex >= DOORMAX) return;
  387.    if(troom->lx > croom->hx) {
  388.       dx = 1;
  389.       dy = 0;
  390.       xx = croom->hx+1;
  391.       tx = troom->lx-1;
  392.       cc = finddpos(xx,croom->ly,xx,croom->hy);
  393.       tt = finddpos(tx,troom->ly,tx,troom->hy);
  394.    } else if(troom->hy < croom->ly) {
  395.       dy = -1;
  396.       dx = 0;
  397.       yy = croom->ly-1;
  398.       cc = finddpos(croom->lx,yy,croom->hx,yy);
  399.       ty = troom->hy+1;
  400.       tt = finddpos(troom->lx,ty,troom->hx,ty);
  401.    } else if(troom->hx < croom->lx) {
  402.       dx = -1;
  403.       dy = 0;
  404.       xx = croom->lx-1;
  405.       tx = troom->hx+1;
  406.       cc = finddpos(xx,croom->ly,xx,croom->hy);
  407.       tt = finddpos(tx,troom->ly,tx,troom->hy);
  408.    } else {
  409.       dy = 1;
  410.       dx = 0;
  411.       yy = croom->hy+1;
  412.       ty = troom->ly-1;
  413.       cc = finddpos(croom->lx,yy,croom->hx,yy);
  414.       tt = finddpos(troom->lx,ty,troom->hx,ty);
  415.    }
  416.     xx = cc.x;
  417.     yy = cc.y;
  418.     tx = tt.x - dx;
  419.     ty = tt.y - dy;
  420.     if(nxcor && levl[xx+dx][yy+dy].typ)
  421.         return;
  422.     dodoor(xx,yy,croom);
  423.  
  424.     cct = 0;
  425.     while(xx != tx || yy != ty) {
  426.         xx += dx;
  427.         yy += dy;
  428.  
  429.         /* loop: dig corridor at [xx,yy] and find new [xx,yy] */
  430.         if(cct++ > 500 || (nxcor && !rn2(35)))
  431.         return;
  432.  
  433.         if(xx == COLNO-1 || xx == 0 || yy == 0 || yy == ROWNO-1)
  434.         return;        /* impossible */
  435.  
  436.         crm = &levl[xx][yy];
  437.         if(!(crm->typ)) {
  438.         if(rn2(100)) {
  439.             crm->typ = CORR;
  440.             crm->scrsym = CORR_SYM;
  441.         } else {
  442.             crm->typ = SCORR;
  443.             crm->scrsym = ' ';
  444.         }
  445.         if(nxcor && !rn2(50)) {
  446.             mkobj_at(ROCK_SYM, xx, yy);
  447.         }
  448.         } else
  449.         if(crm->typ != CORR && crm->typ != SCORR) {
  450.         /* strange ... */
  451.       return;
  452.         }
  453.  
  454.         /* find next corridor position */
  455.         dix = abs(xx-tx);
  456.         diy = abs(yy-ty);
  457.  
  458.         /* do we have to change direction ? */
  459.         if(dy && dix > diy) {
  460.         register int ddx = (xx > tx) ? -1 : 1;
  461.  
  462.         crm = &levl[xx+ddx][yy];
  463.         if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) {
  464.             dx = ddx;
  465.             dy = 0;
  466.             continue;
  467.         }
  468.         } else if(dx && diy > dix) {
  469.         register int ddy = (yy > ty) ? -1 : 1;
  470.  
  471.         crm = &levl[xx][yy+ddy];
  472.         if(!crm->typ || crm->typ == CORR || crm->typ == SCORR) {
  473.             dy = ddy;
  474.             dx = 0;
  475.             continue;
  476.         }
  477.         }
  478.  
  479.         /* continue straight on? */
  480.         crm = &levl[xx+dx][yy+dy];
  481.         if(!crm->typ || crm->typ == CORR || crm->typ == SCORR)
  482.         continue;
  483.  
  484.         /* no, what must we do now?? */
  485.         if(dx) {
  486.         dx = 0;
  487.         dy = (ty < yy) ? -1 : 1;
  488.         crm = &levl[xx+dx][yy+dy];
  489.         if(!crm->typ || crm->typ == CORR || crm->typ == SCORR)
  490.             continue;
  491.         dy = -dy;
  492.         continue;
  493.         } else {
  494.         dy = 0;
  495.         dx = (tx < xx) ? -1 : 1;
  496.         crm = &levl[xx+dx][yy+dy];
  497.         if(!crm->typ || crm->typ == CORR || crm->typ == SCORR)
  498.             continue;
  499.         dx = -dx;
  500.         continue;
  501.         }
  502.    }
  503.     /* we succeeded in digging the corridor */
  504.     dodoor(tt.x, tt.y, troom);
  505.  
  506.     if(smeq[a] < smeq[b])
  507.         smeq[b] = smeq[a];
  508.     else
  509.         smeq[a] = smeq[b];
  510. }
  511.  
  512. make_niches()
  513. {
  514.     register int ct = rn2(nroom/2 + 1)+1;
  515.     while(ct--) makeniche(FALSE);
  516. }
  517.  
  518. makevtele()
  519. {
  520.     makeniche(TRUE);
  521. }
  522.  
  523. makeniche(with_trap)
  524. boolean with_trap;
  525. {
  526.     register struct mkroom *aroom;
  527.     register struct rm *rm;
  528.     register int vct = 8;
  529.     coord dd;
  530.     register int dy,xx,yy;
  531.     register struct gen *gtmp;
  532.  
  533.     if(doorindex < DOORMAX)
  534.       while(vct--) {
  535.         aroom = &rooms[rn2(nroom-1)];
  536.         if(aroom->rtype != 0) continue;    /* not an ordinary room */
  537.         if(rn2(2)) {
  538.         dy = 1;
  539.         dd = finddpos(aroom->lx,aroom->hy+1,aroom->hx,aroom->hy+1);
  540.         } else {
  541.         dy = -1;
  542.         dd = finddpos(aroom->lx,aroom->ly-1,aroom->hx,aroom->ly-1);
  543.         }
  544.         xx = dd.x;
  545.         yy = dd.y;
  546.         if((rm = &levl[xx][yy+dy])->typ) continue;
  547.         if(with_trap || !rn2(4)) {
  548.         rm->typ = SCORR;
  549.         rm->scrsym = ' ';
  550.         if(with_trap) {
  551.             gtmp = newgen();
  552.             gtmp->gx = xx;
  553.             gtmp->gy = yy+dy;
  554.             gtmp->gflag = TELEP_TRAP | ONCE;
  555.             gtmp->ngen = ftrap;
  556.             ftrap = gtmp;
  557.             make_engr_at(xx,yy-dy,"ad ae?ar um");
  558.         }
  559.         dosdoor(xx,yy,aroom,SDOOR);
  560.         } else {
  561.         rm->typ = CORR;
  562.         rm->scrsym = CORR_SYM;
  563.         if(rn2(7))
  564.             dosdoor(xx,yy,aroom,rn2(5) ? SDOOR : DOOR);
  565.         else {
  566.             mksobj_at(SCROLL_SYM,SCR_TELEPORTATION,xx,yy+dy);
  567.             if(!rn2(3)) mkobj_at(0,xx,yy+dy);
  568.         }
  569.         }
  570.         return;
  571.       }
  572. }
  573.  
  574. /* make a trap somewhere (in croom if mazeflag = 0) */
  575. mktrap(num,mazeflag)
  576. register int num,mazeflag;
  577. {
  578.     register struct gen *gtmp;
  579.     register int kind,nopierc,nomimic,fakedoor,fakegold,tryct = 0;
  580.     register xchar mx,my;
  581.  
  582.  
  583.    if(!num || num >= TRAPNUM) {
  584.       nopierc = (dlevel < 4) ? 1 : 0;
  585.       nomimic = (dlevel < 9 || goldseen ) ? 1 : 0;
  586.       if(index(fut_geno, 'M')) nomimic = 1;
  587.       kind = rn2(TRAPNUM - nopierc - nomimic);
  588.       /* note: PIERC = 7, MIMIC = 8, TRAPNUM = 9 */
  589.    } else kind = num;
  590.  
  591.    if(kind == MIMIC) {
  592.         register struct monst *mtmp;
  593.  
  594.       fakedoor = (!rn2(3) && !mazeflag);
  595.       fakegold = (!fakedoor && !rn2(2));
  596.       if(fakegold) goldseen = TRUE;
  597.       do {
  598.          if(++tryct > 200) return;
  599.          if(fakedoor) {
  600.             /* note: fakedoor maybe on actual door */
  601.             if(rn2(2)){
  602.                if(rn2(2))
  603.                   mx = croom->hx+1;
  604.                else mx = croom->lx-1;
  605.                my = somey();
  606.             } else {
  607.                if(rn2(2))
  608.                   my = croom->hy+1;
  609.                else my = croom->ly-1;
  610.                mx = somex();
  611.             }
  612.          } else if(mazeflag) {
  613.             extern coord mazexy();
  614.             coord mm;
  615.             mm = mazexy();
  616.             mx = mm.x;
  617.             my = mm.y;
  618.          } else {
  619.             mx = somex();
  620.             my = somey();
  621.          }
  622.       } while(m_at(mx,my));
  623.       if(mtmp = makemon(PM_MIMIC,mx,my))
  624.           mtmp->mimic =
  625.          fakegold ? '$' : fakedoor ? '+' :
  626.          (mazeflag && rn2(2)) ? AMULET_SYM :
  627.          "=/)%?![<>" [ rn2(9) ];
  628.       return;
  629.    }
  630.    gtmp = newgen();
  631.    gtmp->gflag = kind;
  632.    do {
  633.       if(++tryct > 200){
  634.          free((char *) gtmp);
  635.          return;
  636.       }
  637.       if(mazeflag){
  638.          extern coord mazexy();
  639.          coord mm;
  640.          mm = mazexy();
  641.          gtmp->gx = mm.x;
  642.          gtmp->gy = mm.y;
  643.       } else {
  644.          gtmp->gx = somex();
  645.          gtmp->gy = somey();
  646.       }
  647.    } while(g_at(gtmp->gx, gtmp->gy, ftrap));
  648.    gtmp->ngen = ftrap;
  649.    ftrap = gtmp;
  650.    if(mazeflag && !rn2(10) && gtmp->gflag < PIERC) gtmp->gflag |= SEEN;
  651. }
  652.  
  653. #ifdef DEBUG
  654. dumpit()
  655.    {
  656.    int x, y;
  657.    struct rm *room;
  658.  
  659.    cgetret(); 
  660.  
  661.    /* kludge in making everything visible */
  662.    for(y=0; y < ROWNO; y++)
  663.       for(x=0; x < COLNO-3; x++)
  664.          if ( (room = &levl[x][y])->typ)
  665.             at(x,y, (room->scrsym) ? room->scrsym : '¿');
  666.    }
  667. #endif
  668.